package com.hospital.controller;

import com.hospital.entity.User;
import com.hospital.service.LoginService;
import com.hospital.vo.ResponseVO;
import com.hospital.vo.UserVO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author yuhuan
 * @Date 2022/3/23
 */
@RestController
@RequestMapping("/admin")
public class LoginController {
    Logger logger = LoggerFactory.getLogger(LoginController.class);
    @DubboReference(interfaceClass = LoginService.class,check = false)
    private LoginService loginService;
    /**
     * 用户登录
     * 根据userAccount账号和userPassword密码来登录
     * @param userVO
     * @return
     */
    @RequestMapping("/login")
    public ResponseVO userLogin(UserVO userVO, HttpServletResponse response) {
        logger.debug(">>>>> 登录业务");
//        User user = new User();
//        BeanUtils.copyProperties(userVO, user);
//        String userAccount = user.getUserAccount();
//        String userPasswrod = user.getUserPasswrod();
//        if (!userAccount.equals(userVO.getUserAccount())) {
//            return ResponseVO.buildSuccessInstance(ResponseVO.NUMBER_ACCOUNT);
//        }
//        if (!userPasswrod.equals(userVO.getUserPasswrod())) {
//            return ResponseVO.buildSuccessInstance(ResponseVO.PASSWORD_ERROR);
//        } else {
//            String token = tokenService.getToken(user);
//            logger.debug("message" + token);
//            Cookie cookie = new Cookie("token", token);
//            cookie.setPath("/");
//            response.addCookie(cookie);
//            return loginService.login(userVO);
//        }
        return null;
    }
        /**
         * 添加（注册）用户
         * @param userVO
         * @return
         */
        @PostMapping("/insert")
        public ResponseVO adduser (UserVO userVO){
            logger.debug(">>>>> 注册业务");
            return loginService.insert(userVO);
        }
}

